package boerseTest.mainTest.AssetsTest;

import static org.junit.Assert.*;
import java.lang.reflect.Field;
import org.junit.Before;
import org.junit.Test;

import boerse.main.Asset.*;
import boerse.main.Exceptions.NegativeValueException;
import boerse.main.Exceptions.NotEnoughMoneyException;

public class CashAccountTest {

	private CashAccount cashAccount;
	private Field field;
	
	@Before
	public void setUp() throws NoSuchFieldException, SecurityException {
		cashAccount = new CashAccount("testAccount");

		field = CashAccount.class.getDeclaredField("money");
		field.setAccessible(true);
	}
	
	
	@Test
	public void testAddMoney() throws NegativeValueException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
		cashAccount.addMoney(1000l);

		
		assertEquals("CashAccount should have 1000 cents", 1000l, field.getLong(cashAccount));
	}
	
	
	@Test(expected = NegativeValueException.class)
	public void testAddMoneyNegatvieValueExcepiton() throws NegativeValueException {
		cashAccount.addMoney(-1000l);
	}
	
	
	@Test
	public void testDeterminePrice() throws NegativeValueException {
		cashAccount.addMoney(1000l);
		assertEquals("Ammount of Cash should be 1000 cent", 1000, cashAccount.determinePrice());
	}
	
	
	@Test
	public void testRemoveMoney() throws NegativeValueException, NotEnoughMoneyException, IllegalArgumentException, IllegalAccessException {
		cashAccount.addMoney(1000l);
		cashAccount.removeMoney(300l);
		
		assertEquals("1000 cent minus 300 cent are 700 cent", 700l, field.getLong(cashAccount));
	}
	
	
	@Test(expected = NotEnoughMoneyException.class)
	public void testRemoveMoneyNotEnoughMoneyException() throws NotEnoughMoneyException, NegativeValueException {
		cashAccount.addMoney(1000l);
		cashAccount.removeMoney(1100);
	}
}
